package com.fxkj.cloud.drms.domain.alarm.service;

import com.fxkj.cloud.drms.domain.alarm.AlarmHistoryDomain;
import com.fxkj.cloud.drms.domain.alarm.AlarmStatistics;
import com.fxkj.cloud.drms.domain.alarm.repository.AlarmHistoryDomainRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/4/7 15:30
 */
@Component
public class AlarmHistoryDomainServiceImpl implements AlarmHistoryDomainService {

    private final AlarmHistoryDomainRepository alarmHistoryDomainRepository;

    public AlarmHistoryDomainServiceImpl(AlarmHistoryDomainRepository alarmHistoryDomainRepository) {
        this.alarmHistoryDomainRepository = alarmHistoryDomainRepository;
    }

    @Override
    public Page<AlarmHistoryDomain> list(Integer page, Integer size, UUID deviceId, UUID productId, UUID orgId, Integer alarmLevel, Long startTs, Long endTs, String alarmText, Boolean closed) {
        return alarmHistoryDomainRepository.list(PageRequest.of(page, size), deviceId, productId, orgId, alarmLevel, startTs, endTs, alarmText, closed);
    }

    @Override
    public void save(AlarmHistoryDomain alarmHistoryDomain) {
        alarmHistoryDomainRepository.save(alarmHistoryDomain);
    }

    @Override
    public void saveAll(List<AlarmHistoryDomain> alarmHistoryDomains) {
        alarmHistoryDomainRepository.saveAll(alarmHistoryDomains);
    }

    @Override
    public List<AlarmHistoryDomain> findByDeviceSerialNoAndCodeAndClose(String deviceSerialNo, String code, Boolean closed) {
        return alarmHistoryDomainRepository.findByDeviceSerialNoAndCodeAndClose(deviceSerialNo, code, closed);
    }

    @Override
    public List<AlarmStatistics> productAlarmStatistics(Set<UUID> productIds) {
        return alarmHistoryDomainRepository.productAlarmStatistics(productIds);
    }
}
